<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="../common/jspcommon.jsp"%>
<%@include file="../common/jscss.jsp"%>
<%@include file="../common/selfCss.jsp"%>
<script type="text/javascript"
	src="/third/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript">
	$(function() {
		$("#add_artRoom_form").validate({
			success : function(label) {
				label.text("").addClass("validate_success");
			},
			rules : {
				painter : {
					required : true,
					minlength : 2,
					maxlength : 20
				},
				artSize : {
					required : true

				},
				material : {
					required : true,
					minlength : 2,
					maxlength : 20
				},
				title : {
					required : true,
					minlength : 2,
					maxlength : 16
				}

			},
			messages : {
				painter : {
					required : "请输入画的作者名",
					minlength : "请填写2个以上字",
					maxlength : "请填写20个以下的字"
				},
				artSize : {
					required : "请输入画的作者名",
					minlength : "请填写2个以上字",
					maxlength : "请填写20个以下的字"
				},
				material : {
					required : "请输入画的作者名",
					minlength : "请填写2个以上字",
					maxlength : "请填写20个以下的字"
				},
				title : {
					required : "请输入画的作者名",
					minlength : "请填写2个以上字",
					maxlength : "请填写20个以下的字"
				}

			},
			submitHandler : function() {
				var artist = new Array();
				$(".artist").each(function(i){
						artist.push({
							"name" : $(this).find("#artistName").val(),
							"detail" : $(this).find("#artistDetail").val()
						});
				});
				if(artist.length==0){
					alert("请添加画家");
					return;
				}
				
				$.post("/misc/artRoom/insertArtRoom.htm", {
					jsonData : escape($.toJSON(artist)),
					startDate : $("#startDate").val(),
					endDate : $("#endDate").val(),
					startTime : $("#startTime").val(),
					endTime : $("#endTime").val(),
					description : $("#description").val(),
					title : $("#title").val(),
					subtitle : $("#subtitle").val(),
					cover : $("#cover").val(),
					address : $("#address").val(),
					titlePic:$("#titlePic").val()
				}, function(data) {
					if (data == "success") {
						//artRoomGrid.loadData();
						alert("添加成功,请刷新查看！");
					}
					if (data == "error") {
						$.ligerDialog.warn("系统有点抽经，请稍候重试！");
					}
				});
			}
		});
	});
	//上传封面
	function uploadImg(self) {
		//alert(1111)
		var filepath = $(self).val();
		var extStart = filepath.lastIndexOf(".");
		var ext = filepath.substring(extStart, filepath.length).toUpperCase();
		if (ext != ".PNG" && ext != ".JPG" && ext != ".JPEG" && ext != ".GIF") {
			alert("图片限于png,jpeg,jpg,gif格式");
			return;
		}
		$("#upload_img_form").ajaxSubmit({
			dataType : 'json',
			cache : false,
			success : function(data) {
				//alert(data);
				$("#cover").val(data.imageServer + data.imageUrl);
			},
			error : function(err) {
				alert(err);
			}
		});
		return false;
	}
	//上传banner
	function uploadTitleImg(self) {
		//alert(1111)
		var filepath = $(self).val();
		var extStart = filepath.lastIndexOf(".");
		var ext = filepath.substring(extStart, filepath.length).toUpperCase();
		if (ext != ".PNG" && ext != ".JPG" && ext != ".JPEG" && ext != ".GIF") {
			alert("图片限于png,jpeg,jpg,gif格式");
			return;
		}
		$("#upload_title_form").ajaxSubmit({
			dataType : 'json',
			cache : false,
			success : function(data) {
				//alert(data);
				$("#titlePic").val(data.imageServer + data.imageUrl);
			},
			error : function(err) {
				alert(err);
			}
		});
		return false;
	}
	//验证封面
	function previewImg(imageId) {
		var img_url = $("#" + imageId).val();
		if (!IsNull(img_url)) {
			window.open(img_url);
		} else {
			alert("没有图片，请上传！");
		}
	}
	//添加作者
	/* function $(id) {
		return document.getElementById(id);
	} */
	var row_times = 0;
	function addRow() {
		function $(id) {
		return document.getElementById(id);
		} 
		row_times++;
		var tableObj = $("tab");
		var rowObj = tableObj.insertRow(0);
		rowObj.setAttribute("id", "artist_"+row_times);
		rowObj.setAttribute("class", "artist");
		var cellObj1 = rowObj.insertCell(-1);
		var cellObj2 = rowObj.insertCell(-1);
		var cellObj3 = rowObj.insertCell(-1);
		var cellObj4 = rowObj.insertCell(-1);
		cellObj1.innerHTML = '<input type="button" value="删除"  onclick="delRow('+row_times+')"/>';
		cellObj2.innerHTML = '序号：'+row_times;
		cellObj3.innerHTML = '姓名：' + '<input type="text" style="width: 100px;" id="artistName"/>';
		cellObj4.innerHTML = '介绍：' + '<textarea  id="artistDetail" cols="200" style="width: 200px;">'+row_times+'</textarea>';
	}
	function delRow(obj) {
		function $(id) {
			return document.getElementById(id);
			} 
		var tr = $("artist_"+obj);
			tr.parentNode.removeChild(tr);
	}
</script>

<form id="upload_img_form" enctype="multipart/form-data" method="post"
	action="/misc/artPic/uploadImg.htm">
	<table width="80%" class="def_t"  border="1" cellpadding="0"
		cellspacing="0">
		<tr>
			<td style="width: 100px;">封面图：</td>
			<td colspan="2"><input type="file"
				onchange="uploadImg(this);return false;" style="width: 200px;"
				title="支持jpg、jpeg、gif、png格式，文件小于2M" name="imagef1" id="imagef1" />
				<a href="javascript:;" target="_blank"
				onclick="previewImg('cover');">预览</a> <input name="cover"
				type="hidden" id="cover" value="" /></td>
		</tr>

	</table>
</form>
<form id="upload_title_form" enctype="multipart/form-data" method="post"
	action="/misc/artPic/uploadImg.htm">
	<table width="80%" class="def_t"  border="1" cellpadding="0"
		cellspacing="0">
		<tr>
			<td style="width: 100px;">Banner图：</td>
			<td colspan="2"><input type="file" onchange="uploadTitleImg(this);return false;"
		style="width: 200px;" title="支持jpg、jpeg、gif、png格式，文件小于2M"
		name="imagef1" id="imagef2" /> <a href="javascript:;" target="_blank"
		onclick="previewImg('titlePic');">预览</a> <input name="titlePic"
		type="hidden" id="titlePic" value="" /></td>
		</tr>
	</table>
</form>

<form method="post" id="add_artRoom_form" action="">
	<table width="80%" class="def_t" id="tab" border="1" cellpadding="0" cellspacing="0">
		<tr>
			<td>画家：</td>
			<td colspan="3"><input type="button" value="添加画家"
				onclick="addRow()" />
			</td>
		</tr>
		<tr>
			<td>标题：</td>
			<td colspan="3"><input type="text" id="title" name="title" /></td>
		</tr>
		<tr>
			<td>副标题：</td>
			<td colspan="3"><input type="text" id="subtitle" name="subtitle" /></td>
		</tr>
		<tr>
			<td>开始日期：</td>
			<td colspan="3"><input class="tb_date" type="text"
				id="startDate" readonly="readonly" name="startDate"
				onclick="WdatePicker({el:'startDate',dateFmt:'yyyy-MM-dd',readOnly:true,isShowClear:false});" />
			</td>
		</tr>
		<tr>
			<td>结束日期：</td>
			<td colspan="3"><input class="tb_date" type="text" id="endDate"
				readonly="readonly" name="endDate"
				onclick="WdatePicker({el:'endDate',dateFmt:'yyyy-MM-dd',readOnly:true,isShowClear:false});" />
			</td>
		</tr>
		<tr>
			<td>开馆时间：</td>
			<td colspan="3"><input class="tb_date" type="text"
				id="startTime" readonly="readonly" name="startTime"
				onclick="WdatePicker({el:'startTime',dateFmt:'HH:mm:ss',readOnly:true,isShowClear:false});" />
			</td>
		</tr>
		<tr>
			<td>闭馆时间：</td>
			<td colspan="3"><input class="tb_date" type="text" id="endTime"
				readonly="readonly" name="endTime"
				onclick="WdatePicker({el:'endTime',dateFmt:'HH:mm:ss',readOnly:true,isShowClear:false});" />
			</td>
		</tr>
		<tr>
			<td>描述：</td>
			<td colspan="3"><textarea id="description" name="description"
					cols="200" style="width: 300px"></textarea>
			</td>
		</tr>
		<tr>
			<td>展览馆地址：</td>
			<td colspan="3"><input type="text" id="address" name="address" />
			</td>
		</tr>
		<tr>
			<td colspan="4" align="center">
				<button type="submit">保存</button></td>
		</tr>
	</table>
</form>
</body>
